/**
 * 日志单例
 * @author xialeistudio
 * @date 2016/5/9 0009
 */
'use strict';
const log4js = require('log4js')
		, fs = require('fs');
class Logger {
	constructor() {
		const path = __dirname + '/../logs';
		if (!fs.existsSync(path)) {
			fs.mkdirSync(path, 666);
		}
		//加载配置
		log4js.configure(require(__dirname + '/../log4js.json'));
		this.info('[Logger] initialized');
	}

	info() {
		this.console().info.apply(this.console(), arguments);
	}

	warn() {
		this.console().info.apply(this.console(), arguments);
		this.file().info.apply(this.file(), arguments);
	}

	debug() {
		this.console().debug.apply(this.console(), arguments);
	}

	trace() {
		this.console().trace.apply(this.console(), arguments);
	}

	error() {
		this.console().error.apply(this.console(), arguments);
		this.file().error.apply(this.file(), arguments);
	}

	console() {
		return log4js.getLogger('console');
	}

	file() {
		return log4js.getLogger('file');
	}
}
module.exports = new Logger();